**********Syntax file for Anoll, Allison P., Cindy D. Kam, and Colette Marcellin. "What Does Race Mean?  Racial Disparities in the Public Mind." Journal of Politics**********
*Supplementary appendix: Analysis of 2022 ANES Pilot data

*****Analysis with StataSE17*****

log using "Anoll Kam Marcellin ANES 2022 Pilot Analyses.smcl", replace 

clear
cd "C:\Users\kamcd\Dropbox\CDK WORK\racial disparities essentialism\JOP replication files"
use "Anoll Kam Marcellin ANES 2022 Pilot Data", clear
svyset [pweight=weight]
set scheme s1mono

*****RACE OF RESPONDENT AND PARTY OF WHITES*****
*generate categorical variables for respondents
gen fivegroups = .
replace fivegroups = 1 if ras==1|rpi==1
replace fivegroups = 2 if rbl==1
replace fivegroups = 3 if rwh==1 & eth==1
replace fivegroups = 4 if rwh==1 & pid7>0 & pid7<4
replace fivegroups = 5 if rwh==1 & pid7>4 & pid7<8
lab def fivegroups 1"Asian" 2"Black" 3"Hispanic" 4"White DEM" 5"White GOP"
lab val fivegroups fivegroups
tab fivegroups

*level of nonresponse*
egen gdiff_miss = anycount(gdiffbiol gdiffculture gdiffpolicy), val(-7)
tab gdiff_miss
/*Most people answered these questions*/
/*1 person refused one of the questions; 2 people skipped the entire battery*/
/*1582 people answered ALL of them*/

//Analogous to first set of analyses, proportion agreeing with >1 Q
recode gdiffbiol (1/4=0)(5=1)(else=.), gen(NOT_bio)
recode gdiffculture (1/4=0)(5=1)(else=.), gen(NOT_cul)
recode gdiffpolicy (1/4=0)(5=1)(else=.), gen(NOT_pol)

gen YES_bio = -1*(NOT_bio-1)
gen YES_cul = -1*(NOT_cul-1)
gen YES_pol = -1*(NOT_pol-1)

egen number_agree = anycount(YES_bio YES_cul YES_pol), val(1)
recode number_agree (1 2 3=1)(0=0)(else=.), gen(any_agree)
tab number_agree
svy: reg any_agree i.fivegroups

drop if any_agree==0 /*disputing the underlying premise of the Q*/

recode gdiffbiol (1=1)(2=.75)(3=.5)(4=.25)(5=0)(else=.), gen(diff_bio)
recode gdiffculture (1=1)(2=.75)(3=.5)(4=.25)(5=0)(else=.), gen(diff_cul)
recode gdiffpolicy (1=1)(2=.75)(3=.5)(4=.25)(5=0)(else=.), gen(diff_pol)

*****in text
svy: tab YES_bio
svy: tab YES_cul
svy: tab YES_pol
svy: tab fivegroups YES_bio, row

**********START FIGURE 1**********
gen gdiff1 = gdiffbiol
gen gdiff2 = gdiffculture
gen gdiff3 = gdiffpolicy

forval v = 1/3 {
recode gdiff`v' (1=1)(2 3 4 5=0)(else=.), gen(gdiffgreatdeal`v')
}

forval v = 1/3 {
recode gdiff`v' (2=1)(1 3 4 5=0)(else=.), gen(gdiffalot`v')
}

forval v = 1/3 {
recode gdiff`v' (3=1)(1 2 4 5=0)(else=.), gen(gdiffmoderate`v')
}

forval v = 1/3 {
recode gdiff`v' (4=1)(1 2 3 5=0)(else=.), gen(gdiffalittle`v')
}

//% FOR FULL SAMPLE
foreach j in greatdeal alot moderate alittle {
	preserve
collapse gdiff`j'1-gdiff`j'3 [pweight=weight]
gen id = _n
reshape long gdiff`j', i(id) j(Q)
lab def Q 1 "Biology" 2 "Culture" 3 "Politics"
lab val Q Q
sum
gen gdiff`j'percent = gdiff`j'*100
save gdiff`j'percent, replace
restore
}

//% BY FIVEGROUPS
forval v=1/5 {
foreach j in greatdeal alot moderate alittle {
	preserve
collapse gdiff`j'1-gdiff`j'3 [pweight=weight] if fivegroups==`v'
gen id = _n
reshape long gdiff`j', i(id) j(Q)
lab def Q 1 "Biology" 2 "Culture" 3 "Politics"
lab val Q Q
sum
gen gdiff`j'percent_`v' = gdiff`j'*100
save gdiff`j'percent_`v', replace
restore
}
}

//PLOTTING % FULL SAMPLE
preserve
clear
use gdiffgreatdealpercent, clear
merge 1:1 Q using gdiffalotpercent
merge 1:1 Q using gdiffmoderatepercent, gen(merge3)
merge 1:1 Q using gdiffalittlepercent, gen(merge4)
recode Q (1=1 "Biology")(2=2 "Culture")(3=3 "Racist Policies"), gen(graphorder)
graph hbar gdiffgreatdealpercent gdiffalotpercent gdiffmoderatepercent gdiffalittlepercent, over(graphorder) ///
name(gdiff_all, replace) ///
title("All Respondents", size(medium)) ytitle(" ") xsize(5) ysize(4) graphregion(margin(l+10)) stack asyvars legend(lab(1 "%A Great" "Deal") lab(2 "%A Lot") lab(3 "%Moderate" "Amount") lab(4 "%A Little") symxsize(5) keygap(.5) row(1) forcesize span)
restore

//PLOTTING % FIVE SUBGROUPS
forval v=1/5 {
preserve
use gdiffgreatdealpercent_`v', clear
	gen str10 group`v' = "Asian" if `v'==1
	replace group`v' = "Black" if `v'==2
	replace group`v' = "Latino" if `v'==3
	replace group`v' = "White DEM" if `v'==4
	replace group`v' = "White GOP" if `v'==5
	local h = group`v'
merge 1:1 Q using gdiffalotpercent_`v'
merge 1:1 Q using gdiffmoderatepercent_`v', gen(merge3)
merge 1:1 Q using gdiffalittlepercent_`v', gen(merge4)
recode Q (1=1 "Biology")(2=2 "Culture")(3=3 "Racist Policies"), gen(graphorder)
graph hbar gdiffgreatdealpercent gdiffalotpercent gdiffmoderatepercent gdiffalittlepercent, over(graphorder) ///
name(gdiff_`v', replace) ///
title("`h' Respondents", size(medium)) ytitle(" ") xsize(5) ysize(4) graphregion(margin(l+10)) stack asyvars legend(lab(1 "%A Great" "Deal") lab(2 "%A Lot") lab(3 "%Moderate" "Amount") lab(4 "%A Little") symxsize(5) keygap(.5) row(1) forcesize span size(vvsmall))
restore
}

graph combine gdiff_all gdiff_1 gdiff_2 gdiff_3 gdiff_4 gdiff_5, row(2) ///
title("On average, racial groups differ in outcomes...", size(medsmall)) ///
subtitle("To what extent do you believe these differences are due to...", size(small)) ///
xsize(6.5) ysize(4) imargin(medlarge) iscale(.425) ycommon xcommon
graph export AppendixFigureC1.pdf, replace

*****N's for caption*****
sum gdiffbiol gdiffculture gdiffpolicy
tab fivegroups
**********END FIGURE 1**********

*****cleaning up directory*****
forval v=1/5 {
erase gdiffalittlepercent_`v'.dta
erase gdiffmoderatepercent_`v'.dta
erase gdiffalotpercent_`v'.dta
erase gdiffgreatdealpercent_`v'.dta
}
erase gdiffalittlepercent.dta
erase gdiffmoderatepercent.dta
erase gdiffalotpercent.dta
erase gdiffgreatdealpercent.dta
*****cleaning up directory*****


//% AGREE WITH >1
egen diff_agree = anycount(NOT_bio NOT_cul NOT_pol), val(0)
svy: tab diff_agree
recode diff_agree (0 1=0)(2 3=1)(else=.), gen(morethanone)

*"Conflicting" factors: biology & policy*
svy: tab YES_bio YES_pol

foreach y of varlist morethanone YES_bio YES_cul YES_pol {
	svy: tab `y' fivegroups, col
}

**********START FIGURE 2**********
gen YES_biopol = .
replace YES_biopol =1 if YES_bio==1 & YES_pol==1
replace YES_biopol =0 if YES_bio==1 & YES_pol==0
replace YES_biopol =0 if YES_bio==0 & YES_pol==1
replace YES_biopol =0 if YES_bio==0 & YES_pol==0

tempname memhold
tempfile morethanone_any
postfile `memhold' fivegroups propagree seprop using morethanone_any, replace
forval v=1/5 {
	svy: reg morethanone if fivegroups==`v'
	post `memhold ' (`v') (_b[_cons]) (_se[_cons])
}
postclose `memhold'
	svy: reg morethanone

set scheme s1mono
preserve
use morethanone_any, clear
set obs 6
replace fivegroups = 0 in 6
replace propagree = .8443039 in 6
replace seprop = .0111789 in 6
lab def fivegroups 0 "All Rs" 1"Asian" 2"Black" 3"Latino" 4"White DEM" 5"White GOP"
lab val fivegroups fivegroups
gen UB = propagree + 1.96*seprop
gen LB = propagree - 1.96*seprop
twoway (bar propagree fivegroups, fcolor(gs8)) (rcap UB LB fivegroups, lcolor(black)), xlabel(, valuelabel) xtitle(" ") legend(off) ylabel(0(.25)1) title("(a) Proportion Agree with" ">1 Factor") name(morethanone, replace)
restore

tempname memhold
tempfile biopol
postfile `memhold' fivegroups propagree seprop using biopol, replace
forval v=1/5 {
	svy: reg YES_biopol if fivegroups==`v'
	post `memhold ' (`v') (_b[_cons]) (_se[_cons])
}
postclose `memhold'
svy: reg YES_biopol

preserve
use biopol, clear
set obs 6
replace fivegroups = 0 in 6
replace propagree = .5450189 in 6
replace seprop = .0152015 in 6
lab def fivegroups 0 "All Rs" 1"Asian" 2"Black" 3"Latino" 4"White DEM" 5"White GOP"
lab val fivegroups fivegroups
gen UB = propagree + 1.96*seprop
gen LB = propagree - 1.96*seprop
twoway (bar propagree fivegroups, fcolor(gs8)) (rcap UB LB fivegroups, lcolor(black)), xlabel(, valuelabel) xtitle(" ") legend(off) ylabel(0(.25)1) title("(b) Proportion Agree with" "Biology and Policies") name(biopol, replace)
restore

graph combine morethanone biopol, ycommon row(1) altshrink ysize(2.5) xsize(6.5)
graph export AppendixFigureC2.pdf, replace

*****N's for caption*****
sum morethanone YES_biopol
tab morethanone fivegroup
tab YES_biopol fivegroups

**********END FIGURE 2**********
*****cleaning up directory*****
erase morethanone_any.dta
erase biopol.dta
*****cleaning up directory*****

log close
translate  "Anoll Kam Marcellin ANES 2022 Pilot Analyses.smcl" "Anoll Kam Marcellin ANES 2022 Pilot Analyses.pdf"
